﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

namespace yule.Data.SQL2008
{
    public class Transaction : yule.Data.Transaction
    {
        private System.Data.Common.DbTransaction _dbTransaction;

        public override System.Data.Common.DbParameter CreateDbParameter(string parameterName, object value, System.Data.DbType dbType, System.Data.ParameterDirection direction = ParameterDirection.Input)
        {
            System.Data.SqlClient.SqlParameter parameter = new SqlParameter();

            parameter.ParameterName = parameterName;
            parameter.Value = value;
            parameter.DbType = dbType;
            parameter.Direction = direction;

            return parameter;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dbTransaction"></param>
        public Transaction(DbTransaction dbTransaction)
        {
            this._dbTransaction = dbTransaction;
        }

        protected override System.Data.Common.DbTransaction DbTransaction
        {
            get { return this._dbTransaction; }
        }

        protected override DbDataAdapter CreateDbDataAdapter(DbCommand cmd)
        {
            System.Data.SqlClient.SqlCommand sqlcmd = cmd as System.Data.SqlClient.SqlCommand;
            sqlcmd.Transaction = this.DbTransaction as  SqlTransaction;
            return new System.Data.SqlClient.SqlDataAdapter(sqlcmd);
        }
    }
}
